package com.ruoyi.web.controller.vote;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.vote.domain.HouseVoteT;
import com.ruoyi.vote.service.IHouseVoteTService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 投票项目Controller
 * 
 * @author ruoyi
 * @date 2023-10-07
 */
@RestController
@RequestMapping("/vote/voteProject")
public class HouseVoteTController extends BaseController
{
    @Autowired
    private IHouseVoteTService houseVoteTService;

    /**
     * 查询投票项目列表
     */
   @GetMapping("/list")
    public TableDataInfo list(HouseVoteT houseVoteT)
    {
        startPage();
        List<HouseVoteT> list = houseVoteTService.selectHouseVoteTList(houseVoteT);
        return getDataTable(list);
    }

    @GetMapping("/listVoteProject1/list1")
    public TableDataInfo list1(HouseVoteT houseVoteT)
    {
        startPage();
        houseVoteT.setVoteSts("0");
        List<HouseVoteT> list = houseVoteTService.selectHouseVoteTList(houseVoteT);
        return getDataTable(list);
    }

    /**
     * 导出投票项目列表
     */
   @Log(title = "投票项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseVoteT houseVoteT)
    {
        List<HouseVoteT> list = houseVoteTService.selectHouseVoteTList(houseVoteT);
        ExcelUtil<HouseVoteT> util = new ExcelUtil<HouseVoteT>(HouseVoteT.class);
        util.exportExcel(response, list, "投票项目数据");
    }

    /**
     * 获取投票项目详细信息
     */
     @GetMapping(value = "/{voteId}")
    public AjaxResult getInfo(@PathVariable("voteId") Long voteId)
    {
        return AjaxResult.success(houseVoteTService.selectHouseVoteTByVoteId(voteId));
    }

    /**
     * 新增投票项目
     */
     @Log(title = "投票项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseVoteT houseVoteT)
    {
        houseVoteT.setCreater(getUsername());
        return toAjax(houseVoteTService.insertHouseVoteT(houseVoteT));
    }

    /**
     * 修改投票项目
     */
    @Log(title = "投票项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseVoteT houseVoteT)
    {
        return toAjax(houseVoteTService.updateHouseVoteT(houseVoteT));
    }

    /**
     * 删除投票项目
     */
    @Log(title = "投票项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{voteIds}")
    public AjaxResult remove(@PathVariable Long[] voteIds)
    {
        return toAjax(houseVoteTService.deleteHouseVoteTByVoteIds(voteIds));
    }


    @Log(title = "投票项目", businessType = BusinessType.UPDATE)
    @PutMapping("/changeVoteStatus")
    public AjaxResult changeStatus(@RequestBody HouseVoteT houseVoteT)
    {
        return toAjax(houseVoteTService.updateHouseVoteT(houseVoteT));
    }

    @GetMapping("/updateVoteStatistic/{voteIds}")
    public AjaxResult updateVoteStatistic(@PathVariable Long[] voteIds)
    {
        return toAjax(houseVoteTService.updateVoteStatistic(voteIds));
    }
}
